<template>
  <div class="detailbox border">

    <div class="flexbox">
      <div class="shrinkbox_v2">
        分享比例
      </div>
      <div class="contentbox_v2">
        <el-input v-if="!feildConfig.isReadonly" class="diyinput"
        v-model="editData.sharePct" placeholder="请输入分享比例"
        autocomplete="new-password" @input="setInputData('sharePct')"></el-input>
        <div v-else class="div_input">
          {{ editData.sharePct }}
        </div>
      </div>
      <div class="shrinkbox_v2">
        公司分享比例
      </div>
      <div class="contentbox_v2">
        <el-input v-if="!feildConfig.isReadonly" class="diyinput"
        v-model="editData.companySharePct" placeholder="请输入公司分享比例"
        autocomplete="new-password" @input="setInputData('companySharePct')"></el-input>
        <div v-else class="div_input">
          {{ editData.companySharePct }}
        </div>
      </div>
    </div>


  </div>
</template>

<script setup>
  import { ref, inject, defineEmits } from 'vue'
  // import { useStore } from 'vuex'
  // 注入全局utils工具js
  const $utils = inject('$utils')
  const editData = ref({})
  const feildConfig = ref({
    isReadonly: false
  })

  // 定义emit方法
  const emit = defineEmits()

  const isShowPwd = ref(false)


  function initData(obj) {
    editData.value = obj.data ? obj.data : {}
    feildConfig.value = obj.feildConfig ? obj.feildConfig : feildConfig.value
  }

  function setInputData (feild) {
    switch (feild) {
      case 'sharePct':
        editData.value.companySharePct = parseFloat(
          $utils.numMul(
            (editData.value.sharePct?editData.value.sharePct:0), 
            editData.value.parent.companySharePct,
            6
          )
        )
        break;
      case 'companySharePct':
        editData.value.sharePct = parseFloat(
          $utils.numDiv(
            (editData.value.companySharePct?editData.value.companySharePct:0), 
            editData.value.parent.companySharePct,
            6
          )
        )
        break;
    
      default:
        break;
    }
  }



  function submitData() {
    $utils.post({
      url: '/Api/User/SetSharePct',
      params: {
        userId: editData.value.id,
        sharePct: editData.value.sharePct,
        companySharePct: editData.value.companySharePct,
      },
      showLoading: true,
      ok: (res) => {
        emit('close-dialog', false)
      }
    })
  }

  defineExpose({
    initData,
    submitData
  })

</script>

<style scoped>
.saveBtn {
  background-color: #4999FA;
  color: #fff;
  font-weight: normal;
  font-size: 14px;
  padding: 3px 10px;
  border-radius: 3px;
  margin-right: 10px;
}
.saveBtn:hover {
  /* background-color: #7BB8FB; */
  opacity: 0.8;
  cursor: pointer;
}
.split_title {
  background-color: #EBEEF5;
  font-size: 16px;
  height: 30px;
  align-items: center;
  font-family: '楷体';
  font-weight: bold;
  display: flex;
  position: relative;
}
.split_title_content {
  flex-grow: 1;
  text-align: center;
}
.split_title_btn {
  display: flex;
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  align-items: center;
}
.shrinkbox_v2 {
  width: 80px;
}
.diyinput :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyselect :deep(.el-select__placeholder) {
  font-size: 12px;
}
.diyselect :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
  /* pointer-events: none; */
}
.diyselect :deep(.el-input__wrapper:hover){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyselect :deep(.el-input__wrapper:active){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyselect :deep(.el-select__wrapper) {
  box-shadow: unset !important;
}
.diyinput :deep(.el-textarea__inner){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diydatepicker :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyformitem {
  margin-bottom: 0;
}
.diydatapicker :deep(.el-date-editor){
  width: 100%;
}
.diydatapicker :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyinput :deep(.el-input-group__append){
  border: 0 !important;
  outline: none;
  background-color: unset;
  box-shadow: none;
  padding: 0 10px 0 5px;
  font-weight: bold;
  font-size: 16px;
}
/deep/ input::-webkit-outer-spin-button,
/deep/ input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/ input[type='number'] {
  -moz-appearance: textfield;
}
</style>